import axios,{InternalAxiosRequestConfig,AxiosResponse} from 'axios'
import {getToken } from './auth'

let service= axios.create({
  baseURL:"/api",
  timeout:5000
})

//请求拦截器
service.interceptors.request.use((config:InternalAxiosRequestConfig<any>)=>{

  // 拦截到token 
  if(getToken()){
   
    config.headers['Authorization'] ="Bearer "+ getToken()
  }

  return config
})

// 响应拦截器
service.interceptors.response.use((response: AxiosResponse<any, any>)=>{
  // 处理响应数据

  return response.data
})

export default service